/** @file oct_leaf.h
    @brief Octree leaf */

#ifndef G3_OCT_LEAF_H
#define G3_OCT_LEAF_H

#include <deque>

#include "math/m_intersection.h"
#include "file/f_stream.h"

#include "render/r_frustum.h"
#include "render/batch/b_sorter.h"

namespace G3 {

/** @class OCT_LEAF
    @brief An octree leaf class */
class OCT_LEAF {
    public:
        /**
            @brief Constructor
        */
        OCT_LEAF ();

        /**
            @brief Copy constructor
            @param[in] leaf Reference to the leaf to be copied
        */
        OCT_LEAF (const OCT_LEAF &leaf);

        /**
            @brief Destructor
        */
        ~OCT_LEAF ();

        /** Bounding box of this leaf */
        G3::AABB3F BBox;

		/** Number of batches */
        int num_batches;
		/** Batch offset */
        int batch_offset;
        /** Leaf-frustum visibility cache */
        G3::FRUSTUM_CLASSIFIC leaf_vis_cache;
        /** Pointer to the logger */
        G3::LOG *log;

        /**
            @brief Assignment operator
            @param[in] leaf Reference to the leaf to be assigned to this one
			@return Reference to the freshly assigned leaf
        */
        OCT_LEAF &operator= (const OCT_LEAF &leaf);

        /**
            @brief Clears the leaf
        */
        void clear ();

        /**
            @brief Dumps the leaf
        */
        void dump ();

        /**
            @brief Uploads the leaf
        */
        int upload (std::vector<G3::BATCH> &batches, const G3::VEC3F &pos) const;

        /**
            @brief Removes the leaf
        */
        int upload_removal (std::vector<G3::BATCH> &batches) const;
};

}

#endif // G3_OCT_LEAF_H
